import base64
import io

from odoo import http
from odoo.http import request


class SpreadsheetController(http.Controller):
    @http.route(['/spreadsheet/excel'], type='http', auth="public", csrf=False)
    def get_spreadsheet_content(self, **kwargs):
        spreadsheet_id = int(kwargs['spreadsheet_id'])
        spreadsheet = request.env['spreadsheet.excel'].browse(spreadsheet_id)
        data = io.BytesIO(base64.standard_b64decode(spreadsheet.content))
        filename = "%s.xlsx" % spreadsheet.name
        return http.send_file(data, filename=filename, as_attachment=True)
